﻿using GKQC.DbHelper.ViewModels;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;

namespace GKQC.DbHelper.DbModels
{
    [SugarTable("t_ort_dtl")]
    public class OrtDtlModel
    {
        public OrtDtlModel()
        {
            this.TestDate = DateTime.Now;
            this.CreateDate = DateTime.Now;
            this.ExpireDate = DateTime.Now;
            this.Temp = "25℃/55%RH";
            this.IsModified = true;
            if (this.ElectricViewModels == null)
                this.ElectricViewModels = new List<ElectricViewModel>();
            if (this.SizeViewModels == null)
                this.SizeViewModels = new List<SizeViewModel>();
            if (this.Datas == null)
                this.Datas = new List<OrtDataModel>();
            this.Remark = string.Empty;
            this.Condiction = string.Empty;
        }

        public OrtDtlModel(int electricQty,int sizeQty,int sNo, long headId) :this()
        {
            this.Datas = new List<OrtDataModel>();
            this.ElectricViewModels = new List<ElectricViewModel>();
            this.SizeViewModels = new List<SizeViewModel>();
            this.SNo = sNo;
            this.HeadId = headId;
            GenerateList(electricQty, sizeQty, sNo);
        }

        public void GenerateList(int electricQty, int sizeQty,int sNo)
        {
            ViewModelTrans<OrtDataModel>.GenerateTestList(electricQty, sizeQty, sNo, ElectricViewModels, SizeViewModels);
            this.IsModified = IsModified;
        }

        [SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
        public long Id { get; set; }

        /// <summary>
        /// 单头Id
        /// </summary>		
        public long HeadId { get; set; }
        /// <summary>
        /// 测试次数
        /// </summary>		
        public int SNo { get; set; }
        /// <summary>
        /// 建立日期
        /// </summary>		
        public DateTime? CreateDate { get; set; }
        /// <summary>
        /// 检验人员
        /// </summary>		
        public string CreateUser { get; set; }
        /// <summary>
        /// 修改日期
        /// </summary>		
        public DateTime? ModiDate { get; set; }
        /// <summary>
        /// 修改人
        /// </summary>		
        public string ModiUser { get; set; }
        /// <summary>
        /// 温湿度
        /// </summary>		
        public string Temp { get; set; }
        /// <summary>
        /// 试验时间
        /// </summary>		
        public int TestTime { get; set; }
        /// <summary>
        /// 试验时间
        /// </summary>		
        public DateTime TestDate { get; set; }
        /// <summary>
        /// 到期日期
        /// </summary>		
        public DateTime ExpireDate { get; set; }

        public string Remark { get; set; }

        /// <summary>
        /// 试验条件 20℃ 25℃ -40℃ 105℃ 120℃
        /// </summary>
        public string Condiction { get; set; }

        [SugarColumn(IsIgnore = true)]
        public List<OrtDataModel> Datas { get; set; }

        [SugarColumn(IsIgnore = true)]
        public List<ElectricViewModel> ElectricViewModels { get; set; }
        [SugarColumn(IsIgnore = true)]
        public List<SizeViewModel> SizeViewModels { get; set; }

        [SugarColumn(IsIgnore = true)]
        public bool IsModified { get; set; }

        public string GetTemp()
        {
            string temp = string.Empty;
            if(!string.IsNullOrWhiteSpace(this.Temp) && this.Temp.Contains("/"))
            {
                temp = this.Temp.Split('/')[0];
            }

            return temp;
        }

        public string GetHumidity()
        {
            string temp = string.Empty;
            if (!string.IsNullOrWhiteSpace(this.Temp) && this.Temp.Contains("/"))
            {
                temp = this.Temp.Split('/')[1].Replace("RH",string.Empty);
            }

            return temp;
        }
    }
}
